/***************************************************************************************************
                                项目                :       GimKeyboard
                                处理器				:       ESP32-S3
                                开发环境			:       pio(Arduino)
                                文件				:       led_ws2812b_drv.h
                                说明				:       ws2812b灯珠驱动头文件
                                作者				:       金欣嵘
====================================================================================================

====================================================================================================
                                               修改记录 
====================================================================================================
----------------------------------------------------------------------------------------------------
                                               2023.05.22
----------------------------------------------------------------------------------------------------
                            修改人                  :            金欣嵘
                            修改记录                :            创建文件 
----------------------------------------------------------------------------------------------------
***************************************************************************************************/
#ifndef __LED_WS2812B_DRV_H__
#define __LED_WS2812B_DRV_H__

#include <FreeRTOS.h>
#include <task.h>
#include <semphr.h>
#include <timers.h>
#include <Adafruit_NeoPixel.h>

#define LED_WS2812B_DEBUG           1                                           //是否打印调试信息

#define LED_DRV_STACK_SIZE          2048                                        //任务堆栈大小
#define LED_DRV_TASK_PRIO           5                                           //任务优先级

#define WS2812B_CTRL_PIN            1                                           //用IO1控制
#define WS2812B_NUM                 87                                          //灯珠数量

#define WS2812B_COLOR_PIPE_R        0
#define WS2812B_COLOR_PIPE_G        1
#define WS2812B_COLOR_PIPE_B        2
#define WS2812B_COLOR_PIPE_NUM      3

#define MAX_LED_BRIGHTNESS          255                                         //最大亮度（0xFF）

#define COLOR_CHANGE_DIRECTION_UP   0
#define COLOR_CHANGE_DIRECTION_DOWN 1

class Led2812bDrv
{
    public:
        static uint8_t color_matrix[WS2812B_COLOR_PIPE_NUM][WS2812B_NUM];
        static void init(void);
        static void set_color_as_step(uint8_t color_pipe, uint8_t step, uint8_t direction);

    private:
        static Adafruit_NeoPixel strip;
        static TaskHandle_t led_2812b_task_handler;
        static void set_brightness(uint8_t set_brightness);
        static void fill_graphics_memory_as_pipe(uint8_t color_pipe, uint8_t value);
        static void start_led2812b_task(void *pvParameters);
};

extern Led2812bDrv led_2812b_drv;

#endif
